# repeat_absence
repeat_absence_lab <- iv_robust(repeat_absence ~ absenteeism | Z_absenteeism, data = lab,diagnostics = T)
repeat_absence_lab_pvals <- getParametricPValue(model = repeat_absence_lab,
																		 hypothesis = "upr")

# village_action
village_action_lab <- iv_robust(village_action ~ absenteeism | Z_absenteeism, data = lab,diagnostics = T)
village_action_lab_pvals <- getParametricPValue(model = village_action_lab,
																								hypothesis = "upr")

# efficacy
abs_efficacy_lab <- iv_robust(abs_efficacy ~ absenteeism | Z_absenteeism, data = lab,diagnostics = T)
abs_efficacy_lab_pvals <- getParametricPValue(model = abs_efficacy_lab,
																								hypothesis = "upr")

#setup
control_means <- with(
	lab, 
	c(
		round(mean(repeat_absence[Z_absenteeism == 0],na.rm = TRUE), 2),
		round(mean(village_action[Z_absenteeism == 0],na.rm = TRUE), 2),
		round(mean(abs_efficacy[Z_absenteeism == 0],na.rm = TRUE), 2)
	)
)
control_means <- as.character(control_means)

pval_lines <- c(
	round(repeat_absence_lab_pvals["absenteeism"],3),
	round(village_action_lab_pvals["absenteeism"],3),
	round(abs_efficacy_lab_pvals["absenteeism"],3)
)

hypothesis_lines <- c(
	"upr",
	"upr",
	"upr"
)


sink("03_tables/ABS_norms_efficacy_lab_Z_iv.tex")
print(
texreg(l = list(repeat_absence_lab,
								village_action_lab,
								abs_efficacy_lab),
			 omit.coef = "Intercept", include.rsquared = F,include.rmse = F,
			 table = F, use.packages = F, custom.gof.names = c("Adjusted R^2", "Observations"),
			 digits = 3, include.ci = FALSE,
			 override.pvalues = list(repeat_absence_lab_pvals,
			 												village_action_lab_pvals,
			 												abs_efficacy_lab_pvals),
			 stars = c(0.01, 0.05, 0.1),
			 custom.header = list("Parents should act" = 1, 
			 										 "Community would intervene" = 2,
			 										 "Intervention is effective" = 3),
			 custom.model.names =  c("(1)",
			 												"(2)",
			 												"(3)"),
			 custom.gof.rows = list(
			 	"Control Mean" = control_means,
			 	"$p$-values" = pval_lines,
			 	"Hypothesis" = hypothesis_lines,
			 	"Block FE" = c("No","No","No")),
			 reorder.gof = c(1,2,3,4,6,5)))
sink()